<template>
    <a-card :bordered="false">
        <s-table
            ref="table"
            :columns="columns"
            :data="loadData"
            :alert="options.alert.show"
            bordered
            :row-key="(record) => record.workflowMessagesId"
            :tool-config="toolConfig"
            :row-selection="options.rowSelection"
        >
            <template #operator class="table-operator">
                <a-space>
                    <a-button type="primary" @click="formRef.onOpen()" v-if="hasPerm('flwWorkflowMessagesAdd')">
                        <template #icon><plus-outlined /></template>
                        新增
                    </a-button>
                    <a-button danger @click="deleteBatchFlwWorkflowMessages()" v-if="hasPerm('flwWorkflowMessagesBatchDelete')">删除</a-button>
                </a-space>
            </template>
            <template #bodyCell="{ column, record }">
                <template v-if="column.dataIndex === 'action'">
                    <a-space>
                        <a @click="formRef.onOpen(record)" v-if="hasPerm('flwWorkflowMessagesEdit')">编辑</a>
                        <a-divider type="vertical" v-if="hasPerm(['flwWorkflowMessagesEdit', 'flwWorkflowMessagesDelete'], 'and')" />
                        <a-popconfirm title="确定要删除吗？" @confirm="deleteFlwWorkflowMessages(record)">
                            <a-button type="link" danger size="small" v-if="hasPerm('flwWorkflowMessagesDelete')">删除</a-button>
                        </a-popconfirm>
                    </a-space>
                </template>
            </template>
        </s-table>
    </a-card>
    <Form ref="formRef" @successful="table.refresh(true)" />
</template>

<script setup name="flwworkflowmessages">
    import { message } from 'ant-design-vue'
    import Form from './form.vue'
    import flwWorkflowMessagesApi from '@/api/biz/flwWorkflowMessagesApi'
    const table = ref()
    const formRef = ref()
    const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
    const columns = [
        {
            title: 'MESSAGE_WORKITEM_ID',
            dataIndex: 'messageWorkitemId'
        },
        {
            title: 'MESSAGE_TRACK_ID',
            dataIndex: 'messageTrackId'
        },
        {
            title: 'PROCESS_INSTANCE_ID',
            dataIndex: 'processInstanceId'
        },
        {
            title: 'WF_PROCESS_ID',
            dataIndex: 'wfProcessId'
        },
        {
            title: 'ACTIVITYINSTANCEID',
            dataIndex: 'activityinstanceid'
        },
        {
            title: 'ACTIVITYID',
            dataIndex: 'activityid'
        },
        {
            title: 'MESSAGE_STATE',
            dataIndex: 'messageState'
        },
        {
            title: 'XREF',
            dataIndex: 'xref'
        },
        {
            title: 'OVERTIME_STATUS',
            dataIndex: 'overtimeStatus'
        },
        {
            title: 'SENDER_PERSON',
            dataIndex: 'senderPerson'
        },
        {
            title: 'SENDER_PERSON_PARTYID',
            dataIndex: 'senderPersonPartyid'
        },
        {
            title: 'SENDER_PERSON_CODE',
            dataIndex: 'senderPersonCode'
        },
        {
            title: 'SENDER_DATE',
            dataIndex: 'senderDate'
        },
        {
            title: 'UPDATED_DATE',
            dataIndex: 'updatedDate'
        },
        {
            title: 'COMPLETED_DATE',
            dataIndex: 'completedDate'
        },
        {
            title: 'PROCESSNAME',
            dataIndex: 'processname'
        },
        {
            title: 'ACTIVITYNAME',
            dataIndex: 'activityname'
        },
        {
            title: 'OPERATE_NAME',
            dataIndex: 'operateName'
        },
        {
            title: 'PERFORMER_NAME',
            dataIndex: 'performerName'
        },
        {
            title: 'PERFORMER_PARTYID',
            dataIndex: 'performerPartyid'
        },
        {
            title: 'PERFORMER_CODE',
            dataIndex: 'performerCode'
        },
        {
            title: 'TASK_STATUS',
            dataIndex: 'taskStatus'
        },
        {
            title: 'READ_STATUS',
            dataIndex: 'readStatus'
        },
        {
            title: 'DONE_STATUS',
            dataIndex: 'doneStatus'
        },
        {
            title: 'SUPPLY_STATUS',
            dataIndex: 'supplyStatus'
        },
        {
            title: 'MESSAGE_SOURCE',
            dataIndex: 'messageSource'
        },
        {
            title: 'WF_MESSAGE_TYPE',
            dataIndex: 'wfMessageType'
        },
        {
            title: 'IS_USABLE',
            dataIndex: 'isUsable'
        },
        {
            title: 'WF_MESSAGES_ATT1',
            dataIndex: 'wfMessagesAtt1'
        },
        {
            title: 'WF_MESSAGES_ATT2',
            dataIndex: 'wfMessagesAtt2'
        },
        {
            title: 'WF_MESSAGES_ATT3',
            dataIndex: 'wfMessagesAtt3'
        },
        {
            title: 'WF_MESSAGES_ATT4',
            dataIndex: 'wfMessagesAtt4'
        },
        {
            title: 'WF_MESSAGES_ATT5',
            dataIndex: 'wfMessagesAtt5'
        },
        {
            title: 'SYS_PARTY_CODE',
            dataIndex: 'sysPartyCode'
        },
        {
            title: 'USABLE_STATUS',
            dataIndex: 'usableStatus'
        },
        {
            title: 'CREATE_DATE',
            dataIndex: 'createDate'
        },
        {
            title: 'CREATE_IP',
            dataIndex: 'createIp'
        },
        {
            title: 'CREATE_USER_ID',
            dataIndex: 'createUserId'
        },
        {
            title: 'MODIFY_DATE',
            dataIndex: 'modifyDate'
        },
        {
            title: 'MODIFY_IP',
            dataIndex: 'modifyIp'
        },
        {
            title: 'MODIFY_USER_ID',
            dataIndex: 'modifyUserId'
        },
        {
            title: 'ORDER_CODE',
            dataIndex: 'orderCode'
        },
        {
            title: 'ATTRIBUTE1',
            dataIndex: 'attribute1'
        },
        {
            title: 'ATTRIBUTE2',
            dataIndex: 'attribute2'
        },
        {
            title: 'ATTRIBUTE3',
            dataIndex: 'attribute3'
        },
        {
            title: 'ATTRIBUTE4',
            dataIndex: 'attribute4'
        },
        {
            title: 'ATTRIBUTE5',
            dataIndex: 'attribute5'
        },
        {
            title: 'IF_GETBACK',
            dataIndex: 'ifGetback'
        },
        {
            title: 'AUDIT_STEP_TYPE',
            dataIndex: 'auditStepType'
        },
        {
            title: 'COUNTERSIGN_LOGO',
            dataIndex: 'countersignLogo'
        },
        {
            title: 'WF_AUTHORIZE_TYPE',
            dataIndex: 'wfAuthorizeType'
        },
        {
            title: 'WORKFLOW_ID',
            dataIndex: 'workflowId'
        },
        {
            title: 'STEP_ID',
            dataIndex: 'stepId'
        },
        {
            title: 'SWITCHES',
            dataIndex: 'switches'
        },
        {
            title: 'APPROVAL_USE_TIME',
            dataIndex: 'approvalUseTime'
        },
        {
            title: 'SENDER_CUMAIL',
            dataIndex: 'senderCumail'
        },
        {
            title: 'SENDER_OU',
            dataIndex: 'senderOu'
        },
        {
            title: 'PERFORMER_CUMAIL',
            dataIndex: 'performerCumail'
        },
        {
            title: 'PERFORMER_OU',
            dataIndex: 'performerOu'
        },
    ]
    // 操作栏通过权限判断是否显示
    if (hasPerm(['flwWorkflowMessagesEdit', 'flwWorkflowMessagesDelete'])) {
        columns.push({
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            width: '150px'
        })
    }
    let selectedRowKeys = ref([])
    // 列表选择配置
    const options = {
        alert: {
            show: false,
            clear: () => {
                selectedRowKeys = ref([])
            }
        },
        rowSelection: {
            onChange: (selectedRowKey, selectedRows) => {
                selectedRowKeys.value = selectedRowKey
            }
        }
    }
    const loadData = (parameter) => {
        return flwWorkflowMessagesApi.flwWorkflowMessagesPage(parameter).then((data) => {
            return data
        })
    }
    // 删除
    const deleteFlwWorkflowMessages = (record) => {
        let params = [
            {
                workflowMessagesId: record.workflowMessagesId
            }
        ]
        flwWorkflowMessagesApi.flwWorkflowMessagesDelete(params).then(() => {
            table.value.refresh(true)
        })
    }
    // 批量删除
    const deleteBatchFlwWorkflowMessages = () => {
        if (selectedRowKeys.value.length < 1) {
            message.warning('请选择一条或多条数据')
            return false
        }
        const params = selectedRowKeys.value.map((m) => {
            return {
                workflowMessagesId: m
            }
        })
        flwWorkflowMessagesApi.flwWorkflowMessagesDelete(params).then(() => {
            table.value.clearRefreshSelected()
        })
    }
</script>
